package com.ui;

import java.awt.event.KeyEvent;

import com.ui.element.HexButton;
import com.ui.element.HexComboBox;
import com.ui.element.HexFrame;
import com.ui.element.HexLabel;
import com.ui.element.HexPanel;
import com.ui.element.HexPasswordField;
import com.ui.element.HexTextField;
import com.ui.event.HexKeyCall;

/**
 * @Description test
 * @ClassName LoginUI
 * @Date 2016年12月28日 上午10:42:11
 * @Author yanghao Copyright (c) All Rights Reserved, 2016.
 */
public class LoginUI extends HexFrame {

	private static final long serialVersionUID = -3214668522103694354L;
	//
	HexTextField login_text_name = new HexTextField();
	HexPasswordField login_text_pwd = new HexPasswordField();
	HexComboBox login_sl_type = new HexComboBox();
	//
	final int w = 360;
	final int h = 140;

	public LoginUI() {
		setSize(w, h);
		this.buildView();
		this.buildListener();
	}

	private void buildView() {
		HexPanel pa = new HexPanel();
		pa.setLayout(null);
		add(pa);
		//
		HexLabel lb_0 = new HexLabel("用  户:");
		lb_0.setBounds(12, 15, 50, 20);
		pa.add(lb_0);
		login_text_name.setBounds(60, 15, 100, 20);
		login_text_name.setPlaceholder("请输入登录名");// 当输入框没有内容时,占位显示信息
		pa.add(login_text_name);

		HexLabel lb_1 = new HexLabel("密  码:");
		lb_1.setBounds(180, 15, 50, 20);
		pa.add(lb_1);
		login_text_pwd.setBounds(220, 15, 100, 20);
		login_text_pwd.setPlaceholder("请输入登录密码");// 当输入框没有内容时,占位显示信息
		pa.add(login_text_pwd);

		HexLabel lb_2 = new HexLabel("类  型:");
		lb_2.setBounds(12, 35, 50, 20);
		pa.add(lb_2);
		login_sl_type.setBounds(60, 35, 100, 20);
		login_sl_type.setPlaceholder("请选择类型");// 当选择框没有内容时,占位显示信息
		login_sl_type.addOption("1", "A");// 加一个选择项
		login_sl_type.addOption(new String[] { "2", "B" }, new String[] { "3", "C" });// 加2个
		pa.add(login_sl_type);
		//
		HexButton login_bt_sub = new HexButton("登录");//
		login_bt_sub.setBounds((w - 120) / 2, 70, 120, 20);
		pa.add(login_bt_sub);
		//
		setVisible(true);
	}

	private void buildListener() {
		//回车监听
		HexKeyCall enterListen = new HexKeyCall() {
			public void callBack(KeyEvent e) {
				if (e.getExtendedKeyCode() == 10) {
					login();
				}
			}
		};
		//组件焦点时回车，直接登录
		login_text_name.keyPressedCall(enterListen);
		login_text_pwd.keyPressedCall(enterListen);
		login_sl_type.keyPressedCall(enterListen);
	}

	/**
	 * @Description 回车登录
	 * @param  参数
	 * @return void 返回类型 
	 * @throws
	 */
	protected void login() {
		String name = login_text_name.getText();
		String pwd = String.valueOf(login_text_pwd.getPassword());
		String id = login_sl_type.getShowChar();
		String value = login_sl_type.getShowId();
		System.out.println("input:" + name + "/" + pwd);
		System.out.println("input:" + id + "/" + value);
	}

	public static void main(String[] args) {
		new LoginUI();
	}

}
